package com.liuguang.rabbitmq.service;

import com.liuguang.common.pojo.CommonResult;
import com.liuguang.common.pojo.MqData;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @ClassName: SendEmailService
 * @Description：
 * @Author: wanghr
 * Date: 5:24 PM 2020/10/14
 * Version: 1.0
 */
@Component
public class SendEmailService {
    @Value("${spring.mail.username}")
    private String mailSendFrom;

    @Resource
    private JavaMailSender javaMailSender;

    public CommonResult sendEmail(MqData mqData) {
        Map<String, Object> data = mqData.getData();
        String ip = (String) data.get("ip");
        String username = (String) data.get("username");
        String userEmail = (String) data.get("userEmail");
        String text = username + "你好！，使用非常用ip：" + ip + "登录成功";

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        System.out.println("获取的发送邮箱信息："+mailSendFrom);
//        simpleMailMessage.setFrom(mailSendFrom);
//        simpleMailMessage.setTo(userEmail);
//        simpleMailMessage.setSubject("这是一封邮件来自wwww");
//        simpleMailMessage.setText(text);
//        try {
//            javaMailSender.send(simpleMailMessage);
//        } catch (MailException e) {
//            CommonResult.fail();
//        }
        return CommonResult.success();
    }
}
